package com.runachina.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

/**
 * Created by lyl on 2017/7/31.
 */

public class MyUtils {

    /**
     * @param context
     * @return 获取当前app中的版本代码
     */
    public static int getAppVersionCode(Context context) {
        PackageManager manager;
        PackageInfo info = null;
        manager = context.getPackageManager();
        try {
            info = manager.getPackageInfo(context.getPackageName(), 0);
        } catch (Exception e) {
            e.getMessage();
        }
        return info.versionCode;
    }

    /**
     * 获取app版本名
     */
    public static String getAppVersionName(Context context) {
        PackageManager manager;
        PackageInfo info = null;
        manager = context.getPackageManager();
        try {
            info = manager.getPackageInfo(context.getPackageName(), 0);
        } catch (Exception e) {
            return "";
        }
        return info.versionName;
    }
}
